<template>
</template>

<script>
import {loginWithToken} from '@/network/login'
import {startLoading,endLoading} from '@/network/loading'
export default {
  name: "LoginDgut",
  data(){
    return{
      token:'',
    }
  },
  created(){
    this.token =window.location.search.split("token=")[1].split('&state=')[0];
    this.login();
  },
  methods:{
    async login(){
      startLoading();
      let params = {token:this.token};
      const {code,data,msg} = await loginWithToken(params);
      if(code==200){
        const authority = data.authorities[0].authority;
        window.localStorage.setItem("springBoot-token", data.token);
        window.localStorage.setItem("role", authority);
        if (authority == "ROLE_user") {
          endLoading();
          await this.$router.push("/user");
        }
        if (authority == "ROLE_admin") {
          endLoading();
          await this.$router.push("/admin");
        }
      }else{
        endLoading();
        await this.$router.push("/");
      }
    }
  }
}
</script>

<style scoped>

</style>
